package com.maoye.ossp.bpm.bpmweb.controller.executor;

import java.util.Map;

import net.sf.json.JSONObject;

import com.maoye.ossp.bpm.bpmweb.utils.DataHolder;
import com.maoye.ossp.bpmagent.engine.IProcessInstanceEngine;

public class StartProcessExecutor extends BpmxExecutor {
	private IProcessInstanceEngine engine;

	public StartProcessExecutor(IProcessInstanceEngine engine) {
		this.engine = engine;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String doExecute(DataHolder holder) {
		if (engine == null) {
			throw new RuntimeException("IProcessInstanceEngine未注入");
		}
		String baseInfo = holder.getData(DataHolder.KEY_NODE).toString();
		Map<String, Object> vars = (Map<String, Object>) holder
				.getData(DataHolder.KEY_VARS);
		String userKey = holder.getParameter("userKey").toString();
		return engine.startProcess(baseInfo, JSONObject.fromObject(vars)
				.toString(), userKey);
	}

}
